

function comment_answer(answer_id,question_id,is_login)
{       
    if(is_login)
    {
    	document.getElementById(question_id+'_info').style.display="none";
    }
    else
    {
    	document.getElementById(question_id+'_info').style.display="";
    }
}

function change_page(page)
{
	var hash=window.location.hash;
	var url=window.location.href;
	//alert(url+","+hash);
	url=url.replace(/[?&]*page=.*$/,'');
	if(url.indexOf('?')!=-1)
		url=url+'&page='+page+hash;
	else
		url=url+'?page='+page+hash;
	window.location.href=url;
}

function change_order(type)
{
	var url=window.location.href;
	url=url.replace(/[?&]*order=.*[^&]/,'');
	url=url.replace(/[?&]*page=.*$/,'');
	if(url.indexOf('?')!=-1)
		url=url+'&order='+type;
	else
		url=url+'?order='+type;
	window.location.href=url;
}

function toggle_rank(id)
{
	$(document).ready(function(){
		$("div#"+id).slideToggle();
	});
}

function change_rank(rank)
{
	
	var url=BASE_HOSTPATH+"dr-includes/dr-page-question-list.php?rank="+rank;
	window.location.href=url;
	
}

function change_tag_rank(rank)
{
	//alert(1);
	var url=BASE_HOSTPATH+"dr-includes/dr-page-tag-list.php?rank="+rank
	window.location.href=url;
	
}

function change_user_rank(rank)
{
	//alert(1);
	var url=BASE_HOSTPATH+"dr-includes/dr-page-user-list.php?rank="+rank
	window.location.href=url;
}

function change_list(list)
{
	var url=BASE_HOSTPATH+"dr-includes/dr-page-question-list.php"+"?list="+list;
	window.location.href=url;
}

function vote(vid,type,is_login,answer_id,question_id,user_id)
{
	if(!is_login)
    {
     	comment_answer(answer_id,question_id,is_login);
     	return false;
    }
	var url=BASE_HOSTPATH+"/dr-includes/dr-ajax-question-list.php";
	//var url='dr-ajax-question-list.php';
	var xmlhttp=false;
	if(window.ActiveXObject)
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	else if(window.XMLHttpRequest)
		xmlhttp=new XMLHttpRequest();
	if(!xmlhttp)
	{
		alert("不能创建XMLHTTP实例");
		return false;
	}

	xmlhttp.open("POST",url,true);
	xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	xmlhttp.onreadystatechange=function()
	{
		if(xmlhttp.readyState==4)
		{
			var msg=xmlhttp.responseText;
			if(msg==10)
				alert('您已经对此投过票了，请24小时后再投票，谢谢');
			else if(msg==1)
			{
				if(type=="question_up")
				{
					num=document.getElementById("voteUP-"+vid).innerHTML;
					num++;
					document.getElementById("voteUP-"+vid).innerHTML=num;
				}
				else if(type=="question_down")
				{
					num=document.getElementById("voteDown-"+vid).innerHTML;
					num++;
					document.getElementById("voteDown-"+vid).innerHTML=num;
				}
			}
			else
				alert(msg);
		}
	}

	result="vid="+vid+"&type="+type+"&owner_id="+user_id;;
	result+="&nocache="+new Date().getTime();
	xmlhttp.send(result);
}

function mark_question(question_id,is_login,value)
{
	
	if(!is_login)
	{
		comment_answer(0,question_id,is_login);
		return false;
	}
	
	var mark_type;
	if(value=='关注')
		mark_type='mark';
	else if(value=='取消关注')
		mark_type='cancel_mark';
	
	var url=BASE_HOSTPATH+"/dr-includes/dr-ajax-mark-question.php";
	var xmlhttp=false;
	if(window.ActiveXObject)
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	else if(window.XMLHttpRequest)
		xmlhttp=new XMLHttpRequest();
	if(!xmlhttp)
	{
		alert("不能创建XMLHTTP实例");
		return false;
	}

	xmlhttp.open("POST",url,true);
	xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	xmlhttp.onreadystatechange=function()
	{
		if(xmlhttp.readyState==4)
		{
			var msg=xmlhttp.responseText;
			//alert(msg);
			if(msg==1)
			{
				//alert(msg);
				//document.getElementById("mark-"+question_id).disabled=true;
				if(mark_type=='mark')
					document.getElementById("mark-"+question_id).value='取消关注';
				else if(mark_type=='cancel_mark')
					document.getElementById("mark-"+question_id).value='关注';
				
			}
			else if(msg==0)
			{
				//alert(msg);
			}
			else 
				alert(msg);	
		}
	}

	result="qid="+question_id+"&mark_type="+mark_type;
	result+="&nocache="+new Date().getTime();
	//alert(result);
	xmlhttp.send(result);
}
